using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace Camalon.Drawing.Design
{
	/// <summary>
	/// Summary description for PropertyGridForm.
	/// </summary>
	internal class PropertyGridForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;

		private System.Windows.Forms.PropertyGrid _propertyGrid = new PropertyGrid();

		public PropertyGridForm():this( AnchorPoint.Default)
		{

		}

		public PropertyGridForm(AnchorPoint anchorPoint)
		{
			InitializeComponent();

			this.Controls.Add(_propertyGrid);
			_propertyGrid.Dock = DockStyle.Fill;
			_propertyGrid.CommandsVisibleIfAvailable = false;
			_propertyGrid.ToolbarVisible = false;
			_propertyGrid.PropertySort = PropertySort.NoSort;//NoSort or Alphabetical-->Hides the categories
			_propertyGrid.SelectedObject = new AnchorValue(anchorPoint);// new Camalon.Drawing.AnchorPoint(0,0);
//			_propertyGrid.Name ="MyProp Grid";
//			_propertyGrid.Text ="MyProp Grid";
			_propertyGrid.SendToBack();

		}


		private void InitializeComponent()
		{
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// button1
			// 
			this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.button1.DialogResult = System.Windows.Forms.DialogResult.OK;
			this.button1.Location = new System.Drawing.Point(288, 104);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(40, 24);
			this.button1.TabIndex = 0;
			this.button1.Text = "OK";
			// 
			// button2
			// 
			this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.button2.Location = new System.Drawing.Point(236, 104);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(48, 24);
			this.button2.TabIndex = 1;
			this.button2.Text = "Cancel";
			// 
			// PropertyGridForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(330, 130);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Name = "PropertyGridForm";
			this.Text = "Edit Anchor Value";
			this.ResumeLayout(false);

		}

//		protected override void OnClosed(EventArgs e)
//		{
//			AnchorValue av = _propertyGrid.SelectedObject as AnchorValue;
//			if( av != null) Camalon.Drawing.FileWatcher.WriteLine( av.ToString());
//			base.OnClosed (e);
//		}


		public AnchorPoint GetAnchorValue()
		{
			AnchorValue av = _propertyGrid.SelectedObject as AnchorValue;

			return av.AnchorPoint;

		}

		[Serializable]
		internal class AnchorValue
		{

			AnchorPoint _anchorPoint = AnchorPoint.Default;

			public AnchorValue(  ){}


			public AnchorValue( AnchorPoint anchorPoint ){	_anchorPoint = anchorPoint;	}

			[Browsable( true)]
			[ReadOnly( true)]
			[Category("Edit anchor value")]
			[Description( "You are editing the anchor value for")]
			public Point Point
			{
				get{ return _anchorPoint.Point;}
				set{ _anchorPoint.Point = value;}
			}
		
		
			[Browsable(true)]
			[Description( "Please edit the anchor value of point")]
			[Category("Edit anchor value")]
			[DefaultValue( AnchorStyles.Left|AnchorStyles.Top)]
			public AnchorStyles Anchor
			{
				get{ return _anchorPoint.Anchor;}
				set{ _anchorPoint.Anchor = value;}
			}

			public override string ToString()
			{
				return string.Format("Point = {0},  Anchor ={1}", _anchorPoint.Point, _anchorPoint.Anchor);
			}

			[Browsable( false)]
			public AnchorPoint AnchorPoint
			{
				get{ return _anchorPoint;}
			}
		}

	}


}
